//
//  MJ_UserLoginResult.m
//
//  Created by   on 2017/12/27
//  Copyright (c) 2017 __MyCompanyName__. All rights reserved.
//

#import "MJ_UserLoginResult.h"
#import "MJ_UserLoginUserLoginDetail.h"


NSString *const kMJ_UserLoginResultIsPoolTranslator = @"isPoolTranslator";
NSString *const kMJ_UserLoginResultUserNick = @"userNick";
NSString *const kMJ_UserLoginResultUserLoginDetail = @"userLoginDetail";
NSString *const kMJ_UserLoginResultUserId = @"userId";
NSString *const kMJ_UserLoginResultFacePath = @"facePath";


@interface MJ_UserLoginResult ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation MJ_UserLoginResult

@synthesize isPoolTranslator = _isPoolTranslator;
@synthesize userNick = _userNick;
@synthesize userLoginDetail = _userLoginDetail;
@synthesize userId = _userId;
@synthesize facePath = _facePath;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.isPoolTranslator = [[self objectOrNilForKey:kMJ_UserLoginResultIsPoolTranslator fromDictionary:dict] boolValue];
            self.userNick = [self objectOrNilForKey:kMJ_UserLoginResultUserNick fromDictionary:dict];
            self.userLoginDetail = [MJ_UserLoginUserLoginDetail modelObjectWithDictionary:[dict objectForKey:kMJ_UserLoginResultUserLoginDetail]];
            self.userId = [[self objectOrNilForKey:kMJ_UserLoginResultUserId fromDictionary:dict] doubleValue];
            self.facePath = [self objectOrNilForKey:kMJ_UserLoginResultFacePath fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithBool:self.isPoolTranslator] forKey:kMJ_UserLoginResultIsPoolTranslator];
    [mutableDict setValue:self.userNick forKey:kMJ_UserLoginResultUserNick];
    [mutableDict setValue:[self.userLoginDetail dictionaryRepresentation] forKey:kMJ_UserLoginResultUserLoginDetail];
    [mutableDict setValue:[NSNumber numberWithDouble:self.userId] forKey:kMJ_UserLoginResultUserId];
    [mutableDict setValue:self.facePath forKey:kMJ_UserLoginResultFacePath];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.isPoolTranslator = [aDecoder decodeBoolForKey:kMJ_UserLoginResultIsPoolTranslator];
    self.userNick = [aDecoder decodeObjectForKey:kMJ_UserLoginResultUserNick];
    self.userLoginDetail = [aDecoder decodeObjectForKey:kMJ_UserLoginResultUserLoginDetail];
    self.userId = [aDecoder decodeDoubleForKey:kMJ_UserLoginResultUserId];
    self.facePath = [aDecoder decodeObjectForKey:kMJ_UserLoginResultFacePath];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeBool:_isPoolTranslator forKey:kMJ_UserLoginResultIsPoolTranslator];
    [aCoder encodeObject:_userNick forKey:kMJ_UserLoginResultUserNick];
    [aCoder encodeObject:_userLoginDetail forKey:kMJ_UserLoginResultUserLoginDetail];
    [aCoder encodeDouble:_userId forKey:kMJ_UserLoginResultUserId];
    [aCoder encodeObject:_facePath forKey:kMJ_UserLoginResultFacePath];
}

- (id)copyWithZone:(NSZone *)zone {
    MJ_UserLoginResult *copy = [[MJ_UserLoginResult alloc] init];
    
    
    
    if (copy) {

        copy.isPoolTranslator = self.isPoolTranslator;
        copy.userNick = [self.userNick copyWithZone:zone];
        copy.userLoginDetail = [self.userLoginDetail copyWithZone:zone];
        copy.userId = self.userId;
        copy.facePath = [self.facePath copyWithZone:zone];
    }
    
    return copy;
}


@end
